var orderAllotPageVm  = new Vue({
    el: '#orderAllotPage',
    data: {
        orderAllotPageVisible: false,
        quoteOrderAllotPageVisible: false,
        orderNo: '',
        /* 标品 true, 报价商品 false */
        isStandard: '',
        /* 标品分配门店 */
        storeInfosQuery: [],
        /* 报价商品分配门店 */
        sellerInfoList: [],
        /* 报价商品分配价格 */
        totalPrice: '',
        q:{
            factoryName: ''
        }
    },
    methods: {
        loadData: function (data) {
            orderAllotPageVm.orderNo = data.orderNo;
            $.get(baseURL + "order/erporder/orderAllotFindFactory?orderNo=" + data.orderNo, function(r){
                vm.allotLoading = false;
                if (r.code == 0){
                    orderAllotPageVm.isStandard = r.isStandard;
                    if (orderAllotPageVm.isStandard){
                        orderAllotPageVm.storeInfosQuery = r.storeInfosQuery;
                        orderAllotPageVm.orderAllotPageVisible = true;
                    }else {
                        orderAllotPageVm.totalPrice = r.totalPrice;
                        orderAllotPageVm.sellerInfoList = r.sellerInfoList;
                        orderAllotPageVm.quoteOrderAllotPageVisible = true;
                    }
                }else{
                    alert(r.msg);
                }
            });
        },
        orderAllotSave: function (row) {
            var merchantName, merchantId, totalPrice, self, csRemark;
            if (orderAllotPageVm.isStandard){
                merchantName = row.merchantName;
                merchantId = row.merchantId;
                totalPrice = row.totalPrice;
                csRemark = row.csRemark;
                self = true;
            }else{
                merchantName = row.sellerName;
                merchantId = row.sellerId;
                csRemark = row.csRemark;
                totalPrice = orderAllotPageVm.totalPrice;
                self = true;
            }
            this.$confirm('确认分配至 '+ merchantName +' ?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning',
                callback: function (f) {
                    if (f == 'confirm'){
                        var postData = {
                            orderNo: orderAllotPageVm.orderNo,
                            isStandard: orderAllotPageVm.isStandard,
                            producer: merchantId,
                            cost: totalPrice,
                            self: self,
                            csRemark: csRemark,
                            csId: vm.erpOrder.csId,
                            pmcId: vm.erpOrder.pmcId
                        };
                        $.ajax({
                            type: "POST",
                            url: baseURL + "order/erporder/allotOrder",
                            contentType: "application/json",
                            data: JSON.stringify(postData),
                            success: function(r){
                                if(r.code == 0){
                                    if (orderAllotPageVm.isStandard){
                                        orderAllotPageVm.orderAllotPageVisible = false;
                                    }else {
                                        orderAllotPageVm.quoteOrderAllotPageVisible = false;
                                    }
                                    vm.getInfo(orderAllotPageVm.orderNo);
                                }else{
                                    alert(r.msg);
                                }
                            }
                        });
                    }
                }
            })
        },
        query: function () {

        },
        closeOrderAllotPage: function () {

        },
    }
})